﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace OpenPhotoAlbum.Controls
{
    public class Message: Label
    {
        private const string FAIL_CSS_CLASS = "failMessage";
		private const string SUCCESS_CSS_CLASS = "successMessage";
		private const string VSK_MESSAGE_TYPE = "mt";

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

			this.Text = string.Empty;
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;

                if (!string.IsNullOrEmpty(base.Text))
                {
                    this.Visible = true;
                }
                else
                {
                    this.Visible = false;
                }
            }
        }

		public string MessageType
		{
			get { return ViewState[VSK_MESSAGE_TYPE] as string; }
			set { ViewState[VSK_MESSAGE_TYPE] = value; }
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);

			if (MessageType == MessageTypes.FailMessage) { this.CssClass = FAIL_CSS_CLASS; }
			else if (MessageType == MessageTypes.SuccessMessage) { this.CssClass = SUCCESS_CSS_CLASS; }
		}
    }

	public class MessageTypes
	{
		public const string FailMessage = "f";
		public const string SuccessMessage = "s";
	}
}
